import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:provider/provider.dart';
import 'package:tiktokadult/alert_business/aw_permission_alert.dart';
import 'package:tiktokadult/hj_page/home_business/search_page/widget/common_search_bar_view.dart';
import 'package:tiktokadult/hj_page/home_business/widget/home_txt_marquee.dart';
import 'package:tiktokadult/hj_page/main_page/provider/module_provider.dart';
import 'package:tiktokadult/tools_base/loading/loading_center_widget.dart';

import '../../hj_utils/screen.dart';
import '../../tools_base/global_store/store.dart';
import 'home_main_logic.dart';
import 'home_main_page.dart';
import 'hs_home_drawer.dart';

class DarkHomePage extends StatefulWidget {
  final String? defaultId;
  const DarkHomePage({super.key, this.defaultId});

  @override
  State<DarkHomePage> createState() => _DarkHomePageState();
}

class _DarkHomePageState extends State<DarkHomePage> with SingleTickerProviderStateMixin {
  late HomeMainLogic logic;
  @override
  void initState() {
    super.initState();
    logic = HomeMainLogic(isDarkStyle: true, darkDefaultId: widget.defaultId);
  }

  @override
  Widget build(BuildContext context) {
    return Material(
      color: Color(0xff050f17),
      child: GetBuilder<HomeMainLogic>(
        init: logic,
        tag: "HomeMainLogic_dark",
        builder: (_) {
          return Consumer<DarkWebModuleProvider>(
            builder: (ctx, provider, __) {
              logic.tabController?.index = provider.child;
              return Stack(
                fit: StackFit.expand,
                children: [
                  Scaffold(
                    backgroundColor: Colors.black,
                    endDrawer: Builder(builder: (_) => HSHomeDrawer(logic)),
                    body: () {
                      if (logic.isLoadingData) {
                        return LoadingCenterWidget();
                      } else {
                        return Column(
                          children: [
                            Container(
                              margin: EdgeInsets.only(top: screen.paddingTop),
                              height: kToolbarHeight,
                              child: CommonSearchBarView(isDarkStyle: true),
                            ),
                            Expanded(
                              child: HsHomeTabView(
                                key: ValueKey(logic.tabViewValueKey),
                                logic: logic,
                                //isDarkStyle: true,
                              ),
                            ),
                          ],
                        );
                      }
                    }(),
                  ),
                  Positioned(
                    bottom: 0,
                    left: 0,
                    right: 0,
                    child: HomeTxtMarQuee(typeValue: 1),
                  ),
                  Consumer<GlobalStore>(builder: (_, store, __) {
                    return SizedBox.shrink();
                    if (store.isAWVIP()) return SizedBox.shrink();
                    return Positioned.fill(
                      child: AwPermissionAlert(),
                    );
                  }),
                ],
              );
            },
          );
        },
      ),
    );
  }
}
